package com.itheima.login;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component("log")
@Aspect
public class Test222 {
    @Pointcut("execution(* com.itheima.service.impl.*.*(..))")
    private void pt1(){}
    @Before("pt1()")
    public void  beforeMethod(){
        System.out.println("before111111111111111");
    }
    public Object aroundTest(ProceedingJoinPoint pro){
        Object rvalue=null;
        try {
            Object[] args = pro.getArgs();
            System.out.println("开始记录日志");
            rvalue = pro.proceed(args);
            System.out.println("后置");
            return rvalue;
        } catch (Throwable throwable) {
            throwable.printStackTrace();

        }finally {
            System.out.println("最终");
            return rvalue;
        }
    }

    public Object aroundPringLog(ProceedingJoinPoint pjp){
        Object rtValue = null;
        try{
            Object[] args = pjp.getArgs();//得到方法执行所需的参数
            System.out.println("Logger类中的aroundPringLog方法开始记录日志了。。。前置");
            // method.invoke();
            rtValue = pjp.proceed(args);//明确调用业务层方法（切入点方法）
            System.out.println("Logger类中的aroundPringLog方法开始记录日志了。。。后置");
            return rtValue;
        }catch (Throwable t){
            System.out.println("Logger类中的aroundPringLog方法开始记录日志了。。。异常");
            throw new RuntimeException(t);
        }finally {
            System.out.println("Logger类中的aroundPringLog方法开始记录日志了。。。最终");
        }
    }

    public void returningMethod(){
        System.out.println("return222222222222222222");
    }
    public void throwsing(){
        System.out.println("throws333333333333333333");
    }
}
